{
  lib,
  pkgs,
  config,
  flakeOutputs,
  ...
}:

{
  options.flakeDeclared.desktop.inputMethod = lib.mkOption {
    type = with lib.types; nullOr (enum [ "fcitx5" ]);
  };
  config = lib.mkIf (config.flakeDeclared.desktop.inputMethod == "fcitx5") {
    i18n.inputMethod = {
      enable = true;
      type = "fcitx5";
      fcitx5 = {
        waylandFrontend = true;
        addons =
          let
            enableZhCn = builtins.elem "zh_CN.UTF-8/UTF-8" config.i18n.supportedLocales;
            enableJaJp = builtins.elem "ja_JP.UTF-8/UTF-8" config.i18n.supportedLocales;
          in
          [
            pkgs.fcitx5-m17n
            (pkgs.fcitx5-rime.override (prev: {
              rimeDataPkgs =
                with pkgs;
                [
                  rime-data
                ]
                ++ lib.optionals enableZhCn [
                  flakeOutputs.packages.${config.nixpkgs.hostPlatform.system}.rime-wanxiang
                ];
            }))
          ]
          ++ lib.optionals enableZhCn (
            if config.services.xserver.desktopManager.plasma5.enable then
              [ pkgs.libsForQt5.fcitx5-chinese-addons ]
            else
              [ pkgs.kdePackages.fcitx5-chinese-addons ]
          )
          ++ lib.optionals enableJaJp [
            pkgs.fcitx5-mozc
          ];
      };
    };
  };
}
